package front.avonigo.com;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import controller.avonigo.com.MailController;

@SuppressWarnings("serial")
public class Notification extends HttpServlet {

	private static final Logger log = Logger.getLogger(Notification.class
			.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {

		String strCallResult = "";
		resp.setContentType("text/plain");
		try {

			String strTo = req.getParameter("email");
			MailController.sendNotificationMail(strTo, req.getRemoteHost(),	req.getRemoteAddr());
			strCallResult = "Success: " + "Email has been delivered.";
			resp.getWriter().println(strCallResult);

		} catch (Exception ex) {
			strCallResult = "Fail: " + ex.getMessage();
			log.warning(ex.getMessage());
			resp.getWriter().println(strCallResult);
		}
	}

	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
